import { handleSearchLoading, handleSearchTime } from "@userList/search";
import { IMOptionsType } from "@/types/dict";
import {
  tableActiveKey,
  searchList,
  columns,
  drawerFormState,
  tabPower,
  defaultSearchList,
  defaultColumns,
  resetFormState,
} from "./store";
import { handleAction, refreshTable } from ".";
import { getSelfNodeIcon } from "@system/menu/store";
const searchLoading = ref(false);
const resetLoading = ref(false);
export const searchConfig = () => {
  const defineSearch = {
    okText: getProxyT("base.query"),
    cancelText: getProxyT("base.reset"),
    searchLoading,
    resetLoading,
    refreshTableData: async (searchParams: any, type: any) => {
      handleSearchTime(["start_date", "end_date"], searchParams, "YYYY-MM-DD");
      searchParams.status =
        searchParams.status === "" ? undefined : searchParams.status;
      handleSearchLoading(true, type, defineSearch);
      await refreshTable(searchParams);
      handleSearchLoading(false, type, defineSearch);
    },
    extra: () => {
      const identify =
        "labelApi." + (tableActiveKey.value === 0 ? "create" : "createG");
      return withDirectivePower({
        vNode: (
          <s-button
            type="primary"
            onClick={() => handleAction({ type: "add" })}
            icon={renderIcon(getSelfNodeIcon(identify))}
          >
            {tableActiveKey.value === 0
              ? $t("base.addLabel")
              : $t("base.addLabelGroup")}
          </s-button>
        ),
        bindingValue: identify,
      });
    },
    tabsSlot: {
      on: {
        change(tableActiveKey: any) {
          searchList.value = defaultSearchList[tableActiveKey];
          initObjAttr(columns, defaultColumns[tableActiveKey]);
          resetFormState(drawerFormState);
          refreshTable();
        },
      },
      activeKey: tableActiveKey,
      options: ([] as IMOptionsType[])
        .concat(
          tabPower[0]
            ? {
                label: getProxyT("label6"),
                value: 0,
              }
            : []
        )
        .concat(
          tabPower[1]
            ? {
                label: getProxyT("table75"),
                value: 1,
              }
            : []
        ),
    },
    searchList,
  };

  return defineSearch;
};
